package com.xywy.tangandroid.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xywy.tangandroid.R;
import com.xywy.tangandroid.base.BasicAdapter;
import com.xywy.tangandroid.bean.SystemMessageData;

/**
 * 系统消息适配器
 */
public class SystemMessageAdapter extends BasicAdapter<SystemMessageData> {

	private Context context;
	private List<SystemMessageData> list;
	private LayoutInflater inflater;

	public SystemMessageAdapter(Context context, List<SystemMessageData> list) {
		super(context, list);
		this.context = context;
		this.list = list;
		this.inflater = LayoutInflater.from(context);
	}

	/**
	 * 设置进来添加的数据后通知listview刷新
	 * 
	 * @param list
	 */
	public void setAddList(List<SystemMessageData> list) {
		this.list.addAll(0, list);
		notifyDataSetChanged();
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {

		viewholder holder = null;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.item_system_message, null);
			holder = new viewholder();
			holder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
			holder.tv_content = (TextView) convertView.findViewById(R.id.tv_content);
			holder.tv_date = (TextView) convertView.findViewById(R.id.tv_date);
			holder.ll_root = (LinearLayout) convertView.findViewById(R.id.ll_root);
			convertView.setTag(holder);
		} else {
			holder = (viewholder) convertView.getTag();
		}

		/* 展示数据 */
		holder.tv_title.setText(list.get(position).getTitle());
		holder.tv_content.setText(list.get(position).getContent());
		holder.tv_date.setText(list.get(position).getDatatime());

		if (list.get(position).getState() == 0) { // 已读
		// holder.ll_root.setBackgroundColor(0xffcccccc);
		} else if (list.get(position).getState() == 1) { // 未读
		// holder.ll_root.setBackgroundColor(0xffffffff);
		}
		return convertView;
	}

	private class viewholder {
		LinearLayout ll_root; // 跟布局
		TextView tv_title; // 系统标题
		TextView tv_content; // 系统内容
		TextView tv_date; // 系统内容

	}
}
